<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #ul {

            list-style: none;
        }

        li {
            border-radius: 50%;
            position: absolute;
        }
    </style>
</head>

<body>
    <input type="button" name="" id="pop" value="POP">
    <ul id="ul"></ul>
    <h1 id="id">倒计时：</h1>
    <div>
        <h1>成绩</h1>
        <h2 id="click"></h2>
    </div>

    <script>
        class Ball {
            constructor(number, r, g, b) {
                this.number = number;
            }
            render(number, r, g, b) {
                let li = document.createElement('li');
                let x = random(innerWidth - this.number * 2);
                let y = random(innerHeight - this.number * 2);
                if (y < 0) {
                    y = this.number * 2
                }
                if (x < 0) {
                    x = this.number * 2
                }
                if (y > innerHeight - this.number * 2) {
                    y = innerHeight - this.number * 2
                }
                if (x > innerWidth - this.number * 2) {
                    x = innerWidth - this.number * 2
                }
                let inner = 0.9
                let i = 0;
                let timer = setInterval(function () {
                    i += 2;
                    if (i < number) {
                        li.style.cssText = `
                        width:${i}px;
                        height:${i}px;
                        background-color: rgba(${r},${g},${b},${inner -= 0.009});
                        box-shadow: 3px 3px  10px rgba(${r},${g},${b},${inner -= 0.009});
                        left:${x - i / 2}px;
                        top:${y - i / 2}px;
                        background-color:${this.bkColor};`
                    } else {
                        clearInterval(timer);
                        ul.removeChild(li);
                        timer = null;

                    }
                }, 100)
                li.onclick = function () {
                    clearInterval(timer);
                    ul.removeChild(li);
                    console.log('点中了');
                    count += 1;
                    click.innerText = count;
                }
                ul.appendChild(li);
            }
        }
        let obj = '';
        let count = 0;
        let arr = document.getElementById('id');
        let second = 10;


        pop.onclick = function () {

            //倒计时
            let timer = setInterval(function () {
                if (second >= 0) {
                    id.innerText = second + '秒';
                    console.log(second);
                    second--;
                    let number = random(50, 200);
                    let r = random(255);
                    let g = random(255);
                    let b = random(255);
                    let obj = new Ball(number);
                    obj.render(number, r, g, b);
                    // obj.onmousedown = function (event) {
                    //     console.log(event.target);
                    //     console.log('点中了');
                    //     count += 1;
                    //     click.innerText = count;
                    // }
                } else {
                    id.innerText = 'stop'
                    clearInterval(timer);
                }
            }, 1000);

        }



        // 随机数装封
        function random(min, max) {
            if (!max) {
                [max, min] = [min, 0];
            }
            let number = parseInt(Math.random(min, max) * (max - min + 1) + min);
            return number;
        }
    </script>
    </script>
</body>

</html>